<template>
  <div class="delivery-container">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="收货人">
        <el-input v-model="recipient" placeholder="收货人"></el-input>
      </el-form-item>
      <el-form-item label="收货人电话">
        <el-input v-model="recipientPhone" placeholder="收货人电话"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="searchInfo()">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="list" v-loading="listLoading" element-loading-text="Loading" stripe style="width: 100%">
      <el-table-column type="index" :index="indexMethod" label="行号">
      </el-table-column>
      <el-table-column prop="billNum" label="快递编号" width="120">
      </el-table-column>
      <el-table-column prop="courierCompany" label="快递公司" width="120">
      </el-table-column>
      <el-table-column prop="deliveryAddress" label="收货地址" width="120">
      </el-table-column>
      <el-table-column prop="deliveryTime" label="配送时间" width="180">
      </el-table-column>
      <el-table-column prop="pickupAddress" label="取货地址" width="80">
      </el-table-column>
      <el-table-column prop="recipient" label="配送人电话">
      </el-table-column>
      <el-table-column prop="recipient" label="收货人" width="80">
      </el-table-column>
      <el-table-column prop="recipientPhone" label="收货人电话">
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
          <el-button size="mini" type="success" @click="handleDelete(scope.$index, scope.row)">已完成</el-button>
        </template>
      </el-table-column>

    </el-table>
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
      :page-sizes="[5, 10, 15, 20]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import { getDeliveryTask } from '@/api/delivery/delivery'
export default {
  data() {
    return {
      currentPage: 1,
      pageSize: 5,
      total: 100,
      recipient: "",
      recipientPhone: "",
      listLoading: true,
      list: [],
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      this.listLoading = true;
      getDeliveryTask({
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        recipient: this.recipient,
        recipientPhone: this.recipientPhone
      }).then(res => {
        if (res.code == 200) {
          this.list = res.data.dataList
          this.listLoading = false
        }
      })
    },
    searchInfo() {
      this.fetchData()
    },
    indexMethod(index) {
      return index + 1
    },
  }
}
</script>
